# -*- coding:UTF-8 -*-
import math
class Point:
    def move(self,x,y):
        # 接受x和y两个参数，并且给self对象赋值
        self.x = x
        self.y = y
    def reset(self):
        # 移动到特定位置的move
        self.move(0,0)
    def calculate_distance(self,other_point):
        # 接受另一个Point对象作为输入，返回距离
        return math.sqrt(
            (self.x - other_point.x) ** 2 +
            (self.y - other_point.y) ** 2)
point1 = Point()
point2 = Point()

point1.reset()
point2.move(5,12)
print(point2.calculate_distance(point1))
assert (point2.calculate_distance(point1) == point1.calculate_distance(point2))
point1.move(540,26)
print (point2.calculate_distance(point1))
print (point1.calculate_distance(point2))


class vector:
    def __init__(self,a,b):
        self.a = a
        self.b = b
    def __str__(self):
        return 'vector (%d,%d)'%(self.a,self.b)
    def __add__(self, other):
        return vector(self.a+other.a,self.b+other.b)
A = vector(1501,102)
B = vector(-451,-54)
print (A+B)


class JustCounter:
    __secretCount = 0  # 私有变量
    publicCount = 0  # 公开变量

    def count(self):
        self.__secretCount += 1
        self.publicCount += 1
        print (self.__secretCount)
counter = JustCounter()
counter.count()
print (counter.publicCount)
print ("--------")
counter.count()
print (counter.publicCount)
# print counter.__secretCount  # 报错，实例不能访问私有变量
print (counter._JustCounter__secretCount)

'''
# 子类继承
# 一定要用 super(Student, self).__init__(name, gender) 去初始化父类，否则，继承自 Person 的 Student 将没有 name 和 gender。
# 函数super(Student, self)将返回当前类继承的父类，即 Person ，然后调用__init__()方法，注意self参数已在super()中传入，在__init__()中将隐式传递，不需要写出（也不能写）。
class Person(object):  # 父类
    def __init__(self,name,gender):
        self.name = name
        self.gender = gender
    def whoAmI(self):
        return 'Person name is: %s' % self.name,'gender is: %s' % self.gender
class Student(Person):
    def __init__(self,name,gender,score,age):
        super(Student,self).__init__(name,gender)
        self.score = score
        self.age = age
    def whoAmI(self):
        return 'Student name is: %s' % self.name, 'gender : %s' % self.gender,\
               'score : %d' % self.score,'age : %d' % self.age
class Teacher(Person):
    def __init__(self,name,gender,language,age,):
        super(Teacher,self).__init__(name,gender)
        self.language = language
        self.age = age
    def whoAmI(self):
        return 'Teacher name is: %s' % self.name, 'gender: %s' % self.gender, \
               'language : %s' % self.language,'age: %s' % self.age
def who_am_i(x):
    print x.whoAmI()

p = Person('Tim','Male')
s = Student('Bob','Male',500,21)
t = Teacher('Alice', 'Female', 'English',24)
who_am_i(p)
who_am_i(s)
who_am_i(t)
'''

'''多重继承'''

class Chinese(object):
    def __init__(self,tangshi,**kw):
        self.tangshi = tangshi
        for k,v in kw.iteritems():
            setattr(self,k,v)
    def langauge(self):
        return 'tangshi :%s'% self.tangshi,
class Songci(Chinese):
    def __init__(self,tangshi,songci):
        super(Songci, self).__init__(tangshi)
        self.songci = songci
    def langauge(self):
        return 'songci :%s'% self.songci,'tangshi :%s'% self.tangshi
class Hanfu(Chinese):
    def __init__(self,tangshi,hanfu):
        super(Hanfu, self).__init__(tangshi)
        self.hanfu = hanfu
    def langauge(self):
        return 'hanfu :%s' % self.hanfu,'tangshi :%s' % self.tangshi

class Yuanqu(Songci,Hanfu):
    def __init__(self,tangshi,sognsi,hagnfu,yuanqu):
        super(Yuanqu,self).__init__(tangshi,sognsi,hagnfu)
        self.yuanqu = yuanqu
    def langauge(self):
        return 'tangshi :%s' % self.tangshi,'yuanqu:%s' % self.yuanqu,\
               'songci:%s'% self.songci,'hanfu:%s' % self.hanfu


if __name__ == '__main__':
    def Whichlanguage(x):
        print (x.langauge())

    A = Chinese('tanhsi1')
    B = Songci('tangshi0','sognci0')
    C = Hanfu('tangshi2','hangfu2' )
    D = Yuanqu('tanhsi1','sognci1','hangfu1','yuanqu1',)
    Whichlanguage(A)
    Whichlanguage(B)
    Whichlanguage(C)
    Whichlanguage(D)